package com.yuwei.user

import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.yuwei.base.BaseActivity
import com.yuwei.common.path.RouterPath
import com.yuwei.user.databinding.ActivityRegisterBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.MODULE_REGISTER_ACTIVITY)
class RegisterActivity : BaseActivity<ActivityRegisterBinding, UserViewModel>() {
    override fun initView() {
        binding.register.setOnClickListener {
            if(binding.etPassword.text.toString()!=binding.etRePassword.text.toString()){
                ToastUtils.showLong("两次密码不一致")
                return@setOnClickListener
            }
            if(binding.etUsername.text.toString().isEmpty()||binding.etPassword.text.toString().isEmpty()||binding.etRePassword.text.toString().isEmpty()){
                ToastUtils.showLong("用户名或密码不能为空")
                return@setOnClickListener
            }
            vm.register(binding.etUsername.text.toString(),binding.etRePassword.text.toString())
        }
        binding.goLogin.setOnClickListener {
            finish()
        }
    }

    override fun initData() {
        vm.registerSuccess.observe(this){
            ToastUtils.showLong("注册成功")
            finish()
        }
    }

}